package cn.iocoder.yudao.module.ai.service.componentrepository;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.ai.controller.admin.componentrepository.vo.*;
import cn.iocoder.yudao.module.ai.dal.dataobject.componentrepository.ComponentRepositoryDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.ai.dal.mysql.componentrepository.ComponentRepositoryMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;

/**
 * 组件库 Service 实现类
 *
 * @author gt
 */
@Service
@Validated
public class ComponentRepositoryServiceImpl implements ComponentRepositoryService {

    @Resource
    private ComponentRepositoryMapper componentRepositoryMapper;

    @Override
    public Long createComponentRepository(ComponentRepositorySaveReqVO createReqVO) {
        // 插入
        ComponentRepositoryDO componentRepository = BeanUtils.toBean(createReqVO, ComponentRepositoryDO.class);
        componentRepositoryMapper.insert(componentRepository);
        // 返回
        return componentRepository.getId();
    }

    @Override
    public void updateComponentRepository(ComponentRepositorySaveReqVO updateReqVO) {

        // 更新
        ComponentRepositoryDO updateObj = BeanUtils.toBean(updateReqVO, ComponentRepositoryDO.class);
        componentRepositoryMapper.updateById(updateObj);
    }

    @Override
    public void deleteComponentRepository(Long id) {

        // 删除
        componentRepositoryMapper.deleteById(id);
    }


    @Override
    public ComponentRepositoryDO getComponentRepository(Long id) {
        return componentRepositoryMapper.selectById(id);
    }

    @Override
    public PageResult<ComponentRepositoryDO> getComponentRepositoryPage(ComponentRepositoryPageReqVO pageReqVO) {
        return componentRepositoryMapper.selectPage(pageReqVO);
    }

}